//
//  BYNetworkCache.m
//  BTCBOX
//
//  Created by biyunkeji on 2017/11/29.
//  Copyright © 2017年 jianfengChen. All rights reserved.
//

#import "NetworkCache.h"
#import "PINCache.h"
@implementation NetworkCache

static PINCache *pinCache = nil;

+ (void)pathName:(NSString *)name {
    NSString *cachePath = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES).firstObject;
    cachePath = [cachePath stringByAppendingPathComponent:@"com.pinterest.PINDiskCache.PINCacheShared"];
    cachePath = [cachePath stringByAppendingPathComponent:name];
    pinCache = [[PINCache sharedCache] initWithName:@"name" rootPath:cachePath];
}

+ (void)saveResponseCache:(id <NSCoding>)responseCache forKey:(NSString *)key {
    if (pinCache == nil) {
        pinCache = [PINCache sharedCache];
    }
    [pinCache setObject:responseCache forKey:key];
}

+ (id)getResponseCacheForKey:(NSString *)key {
    if (pinCache == nil) {
        pinCache = [PINCache sharedCache];
    }
    return [pinCache objectForKey:key];
}

+ (void)removeResponseCacheForKey:(NSString *)key {
    if (pinCache == nil) {
        pinCache = [PINCache sharedCache];
    }
    [pinCache removeObjectForKey:key];
}

+ (void)removeAllResponseCache {
    if (pinCache == nil) {
        pinCache = [PINCache sharedCache];
    }
    [pinCache removeAllObjects];
}

@end
